package red.util;

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

public class BaseAction extends ActionSupport {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public Model getParams(){
		HttpServletRequest req = null;
		req = getRequest();
		Model model = new Model();
		Enumeration<String> pNames = req.getParameterNames();
		while(pNames.hasMoreElements()){
			String name = (String) pNames.nextElement();
			String [] values = req.getParameterValues(name);//一个参数可能对应多个值  转化为数组
			String value = "";
			if(values!=null){
				for(int i=0;i<values.length;i++){
					value += values[i] + ",";
				}
				value = value.substring(0,value.length()-1);
			}
			model.put(name, value);
		}
		return model;
	}

	public static HttpServletRequest getRequest(){
		return (HttpServletRequest) ServletActionContext.getRequest();
	}
}
